# 使用centos7作为基础镜像
FROM centos:7

VOLUME /tmp
ENV JAVA_OPTS=""

MAINTAINER seata<448341911@qq.com>

# 设置一个时区环境变量
ENV TZ=Asia/Shanghai
# 添加时间（可选择）
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN echo $TZ >/etc/timezone
# 添加压缩包到容器目录 /usr/java/jdk 中
ADD jdk-8u301-linux-x64.tar.gz /usr/java/jdk/

ONBUILD COPY app.jar app.jar

ARG ARTHAS_VERSION=3.7.1
ARG MIRROR=false

ENV MAVEN_HOST=https://repo1.maven.org/maven2 \
    ALPINE_HOST=dl-cdn.alpinelinux.org \
    MIRROR_MAVEN_HOST=https://maven.aliyun.com/repository/public \
    MIRROR_ALPINE_HOST=mirrors.aliyun.com


# 构建镜像时运行的命令

RUN yum install vim -y && \
    yum install iputils-ping -y && \
    yum install net-tools -y && \
    yum install iproute -y


# if use mirror change to aliyun mirror site
RUN if $MIRROR; then MAVEN_HOST=${MIRROR_MAVEN_HOST} ;ALPINE_HOST=${MIRROR_ALPINE_HOST} ; sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_HOST}/g" /etc/apk/repositories ; fi && \
    # https://github.com/docker-library/openjdk/issues/76
    apk add --no-cache tini && \ 
    # download & install arthas
    wget -qO /tmp/arthas.zip "${MAVEN_HOST}/com/taobao/arthas/arthas-packaging/${ARTHAS_VERSION}/arthas-packaging-${ARTHAS_VERSION}-bin.zip" && \
    mkdir -p /opt/arthas && \
    unzip /tmp/arthas.zip -d /opt/arthas && \
    rm /tmp/arthas.zip


# 设置环境变量
ENV JAVA_HOME /usr/java/jdk/jdk1.8.0_301
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

# 将 Java 和 Arthas 的路径添加到 PATH 环境变量中
ENV PATH $JAVA_HOME/bin:/opt/arthas/as.sh:$PATH


ENTRYPOINT ["/sbin/tini", "--", "java", "$JAVA_OPTS", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
